package cn.rdq.iknesssystem.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment) {

        // 设置要显示Swagger的环境
        Profiles profiles = Profiles.of("dev", "test");

        // 判断是否处在自己设定的环境的值
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                // 配置是否启动
                .enable(flag)
                // 配置分组
                .groupName("hellop1g")
                .select()
                // RequestHandlerSelectors配置扫描接口方式
                // basePackage:指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("cn.rdq.iknessplatform.controlller"))
                // 过滤什么路径
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket user01() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("user01");
    }

    @Bean
    public Docket user02() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("user02");
    }

    @Bean
    public Docket user03() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("user03");
    }

    public ApiInfo apiInfo() {
        Contact contact = new Contact("hellop1g", "http://127.0.0.1/hellop1g", "302995126@qq.com");
        return new ApiInfo("委屈蛤蟆的 Api 文档",
                "Api 文档描述",
                "1.0",
                "http://127.0.0.1",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

}
